import scrapy
from scrapy import cmdline
from xl.items import XlItem

class BaiduSpider(scrapy.Spider):
    # 爬虫的名称 唯一的标识
    name = 'baidu'
    # 允许的域名
    # allowed_domains = ['baidu.com']
    # 起始地址  存放种子URL
    start_urls = ['http://www.baidu.com/']

    def start_requests(self):
        url = self.start_urls[0]
        yield scrapy.Request(url=url,callback=self.xialuo)

    def xialuo(self,response):
        print('11111')
        # print(response.text)
        # 使用items
        item = XlItem()
        item['content'] = response.text
        yield item

    # 回调函数  可以自己改
    # def parse(self, response):
        # self.log(response.text)
        # print(response.text)
        #  scrapy shell  方便调试
        # t(i.xpath('.//a[@class="link-title link-statistics"]/text()').extract_first())

if __name__ == '__main__':
    cmdline.execute('scrapy crawl baidu'.split())